package com.simon.mengkou.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.simon.mengkou.R;
import com.simon.mengkou.data.bean.base.Category;
import com.simon.mengkou.data.bean.base.GoodTopic;
import com.simon.mengkou.data.enums.EEventId;
import com.simon.mengkou.system.global.OuerApplication;
import com.simon.mengkou.system.global.OuerDispatcher;

import com.umeng.analytics.MobclickAgent;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by xiazhenshui on 16/7/24.
 */

public class MallCategoryAdapter extends AbsAdapter<Category> {

    public MallCategoryAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        final Holder holder;
        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.layout_mall_category_item, null);
            holder = new Holder();
            convertView.setTag(holder);
            ButterKnife.bind(holder, convertView);
        } else {
            holder = (Holder) convertView.getTag();
        }

        final Category data = getItem(position);

        if(data.getImage() != null) {
            OuerApplication.mImageLoader.loadImage(holder.mSdvImage, data.getImage().getUrl());
        }

        holder.mSdvImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MobclickAgent.onEvent(mContext, EEventId.MALL_PRODUCT_CATEGORY);
                OuerDispatcher.presentProductListActivity(mContext, data.getId(), data.getName());
            }
        });

        holder.mTvName.setText(data.getName());


        return convertView;
    }


    /**
     * @author zhenshui.xia
     */
    class Holder {
        //图片
        @Bind(R.id.category_id_image)
        SimpleDraweeView mSdvImage;
        //分类名
        @Bind(R.id.category_id_name)
        TextView mTvName;

    }
}
